package com.s4j.core.manager.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.s4j.core.conset.Constant;
import com.s4j.core.hibernate.CommonDao;
import com.s4j.core.manager.model.SysButton;

@Service
public class MenuButtonService {
	
	@Resource
	private CommonDao dao;

	public List<SysButton> createMenuButton(Long menuId) {
		String hql = "from SysButton sb where sb.menu.menuId = ? order by sb.sortNum asc";
		List<SysButton> menuButtons = dao.findByHQL(hql, SysButton.class, menuId);
		removeNotValid(menuButtons);
		return menuButtons;
	}
	
	private void removeNotValid(List<SysButton> menuButtons) {
		for(int i=0; i<menuButtons.size(); i++) {
			SysButton sb = menuButtons.get(i);
			if(sb.getValid().shortValue() == Constant.SYS_BUTTON_VALID_NO) {
				menuButtons.remove(i);
				i--;
			}
		}
	}

}
